<template>
  <div class="app-container ">
    <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="180px">
      <el-tabs v-model="activeName">
        <el-row>
          <el-col :span="24">
            <el-form-item label="系统编号">
              {{ form.seed }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="IP地址">
              {{ form.ip }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="域名">
              {{ form.domainname }}
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="授权码">
              <el-input v-model="form.secret" auto-complete="off" clearable placeholder="授权码" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" :loading="loading" type="primary" @click="submit">保存</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
  export default {
    name: 'Sitesetupauthorization',
    components: {},
    data() {
      return {
        form: {},
        loading: false,
        activeName: '系统授权',
        rules: {}
      }
    },
    mounted() {
      this.$api.post('/authorization/getInfo').then(res => {
        this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
        this.setDefaultVal('keyword')
      })
    },
    methods: {
      submit() {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            this.$api.post('/authorization/update', this.form).then(res => {
              this.$api.post('/Upgrade/index').then(res => {
                this.$message({
                  message: '操作成功',
                  type: 'success'
                })
                this.loading = false
              }).catch(() => {
                this.loading = false
              })
            }).catch(() => {
              this.loading = false
            })
          }
        })
      },
      setDefaultVal(key) {
        if (this.form[key] == null || this.form[key] == '') {
          this.form[key] = []
        }
      }
    }
  }
</script>
